package com.qiyue.admin.biz.base.dict;

import com.ace.cache.annotation.Cache;
import com.qiyue.admin.entity.base.dict.DictValue;
import com.qiyue.admin.repository.base.dict.DictValueRepositroy;
import com.qiyue.common.biz.BaseBiz;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * created by yebinghuan on 2018/4/2
 *
 *  数据字典 使用到了 A神写的AG-Merge 数据聚合  其返回值只能是MAP类型的
 */
@Service
public class DictValueBiz extends BaseBiz<DictValueRepositroy, DictValue,Long> {


    @Cache(key = "dictValue:page:code{1}")
    public List<DictValue> pageDictValueByCode(String code){
        String fitlers="RLIKE_code ="+code;
        String sorts = "orderNum";
        return  this.findList(fitlers,sorts);
    }


    /**
     *  获取 对应的 数据字典键值对
     * @param code
     * @return
     */
    @Cache(key = "dictValue:code{1}")
    public Map<String,String> getDictValueByCode(String code){
        String fitlers="RLIKE_code ="+code;
        Map<String, String> result = this.findDistinctList(fitlers).stream().collect(
                Collectors.toMap(DictValue::getValue, DictValue::getLabelDefault));
        return result;
    }




}
